X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/38c7d3f9eb7d63937c6654ff5dd6046ce02dd59c..74c155708d85abfc2cf227c08de4f27003015b3f:/Super%20Polarity/Actors/MainShip.cs diff --git a/Super Polarity/Actors/MainShip.cs b/Super Polarity/Actors/MainShip.cs index 1f4f22a..616f16e 100644 --- a/Super Polarity/Actors/MainShip.cs +++ b/Super Polarity/Actors/MainShip.cs @@ -20,7 +20,11 @@ namespace SuperPolarity protected bool Shooting; protected int ShotCooldown; - public MainShip(Game newGame) : base(newGame) {} + protected float CurrentImmortalTime; + protected float MaxImmortalTime; + protected bool Flashing; + + public MainShip(SuperPolarity newGame) : base(newGame) {} ~MainShip() { @@ -38,6 +42,13 @@ namespace SuperPolarity SetPolarity(Polarity.Positive); ShotCooldown = 50; + MaxImmortalTime = 1500; + + BoxDimensions.X = 2; + BoxDimensions.Y = 2; + BoxDimensions.W = 2; + BoxDimensions.Z = 2; + InitBox(); BindInput(); } @@ -57,7 +68,11 @@ namespace SuperPolarity protected void HandleShot(float value) { - Children.Add(ActorFactory.CreateBullet(Position, Angle)); + var bullet = ActorFactory.CreateBullet(Position, Angle); + + Children.Add(bullet); + bullet.Parent = this; + Shooting = true; Timer t = new Timer(new TimerCallback(UnlockShot)); t.Change(ShotCooldown, Timeout.Infinite); @@ -97,6 +112,7 @@ namespace SuperPolarity { base.SwitchPolarity(); SwitchParticleEngine(CurrentPolarity); + game.Player.ResetMultiplier(); } public override void SetPolarity(Polarity newPolarity) @@ -127,9 +143,35 @@ namespace SuperPolarity particleEngine.EmitterLocation = Position; particleEngine.Update(); ConstrainToEdges(); + UpdateImmortality(gameTime); Shooting = false; } + public void UpdateImmortality(GameTime gameTime) + { + if (Immortal) + { + CurrentImmortalTime += gameTime.ElapsedGameTime.Milliseconds; + + if (Flashing) + { + Color = new Color(255, 255, 255, 128); + } + else + { + Color = Color.White; + } + + Flashing = !Flashing; + + if (CurrentImmortalTime > MaxImmortalTime) + { + Immortal = false; + Color = Color.White; + } + } + } + public override void Move(GameTime gameTime) { base.Move(gameTime); @@ -207,5 +249,28 @@ namespace SuperPolarity particleEngine.Draw(spriteBatch); base.Draw(spriteBatch); } + + public override void Collide(Actor other, Rectangle collision) + { + if (other.GetType().IsAssignableFrom(typeof(StandardShip)) && + !Immortal) + { + Die(); + } + } + + protected override void Die() + { + game.Player.Lives = game.Player.Lives - 1; + game.Player.ResetMultiplier(); + if (game.Player.Lives < 0) + { + Dying = true; + } + else { + Immortal = true; + CurrentImmortalTime = 0; + } + } } }